# Maintainer: Diego Sogari <diego.sogari@gmail.com>

_realname=sqlightning
pkgbase=mingw-w64-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
provides=("${MINGW_PACKAGE_PREFIX}-sqlite3")
conflicts=("${MINGW_PACKAGE_PREFIX}-sqlite3")
pkgver=3.7.17.r18.bb8144e
pkgrel=1
pkgdesc="SQLite3 ported to use LMDB instead of its original Btree code (mingw-w64)"
arch=('any')
url="https://github.com/LMDB/sqlightning"
license=('PublicDomain')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
depends=("${MINGW_PACKAGE_PREFIX}-ncurses"
         "${MINGW_PACKAGE_PREFIX}-readline")
source=("${_realname}"::"git+https://github.com/LMDB/sqlightning.git")
sha256sums=('SKIP')

pkgver() {
  cd "${srcdir}/${_realname}"
  printf "3.7.17.r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cd "${srcdir}/${_realname}"
  sed -e "s/@LDFLAGS@/& -no-undefined/g" -i Makefile.in
}

build() {
  rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  ../${_realname}/configure \
    --prefix=${MINGW_PREFIX} \
    --{build,host}=${MINGW_CHOST} \
    --disable-tcl

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
}
